<template>
	<view class="shiming-box">
		<view class="shiming">
			
		</view>
		<view class="title">
			{{proName}}
		</view>
		<view class="box">
			<view class="row">
				<view class="left">
					客户姓名
				</view>
				<input type="text" style="opacity: 1" readonly="readonly" @click="selectCustom" :value="customer.custno" class="username" placeholder="请输入您的真实姓名" v-model="customer.name"/>
				<input type="hidden" style="display:none" value="" placeholder="" v-model="customer.custno"/>
			</view>
			<view class="row">
				<view class="left">
					预约金额
				</view>
				<input type="number" class="inputMoney" value="" placeholder="请输入金额" v-model="balance"/>
				万元
			</view>
			
			<!-- <view class="row">
				<view class="left">
					预约日期
				</view>
				<view class="right">
					<timePicker @change="showTime"></timePicker>
				</view>
			</view> -->
			
		</view>
		<view class="questionBox">
			<view class="question" @click="tijiao">
				<label class="iconfont icon">&#xe66a;</label>提交
			</view>
		</view>
	</view>
</template>

<script>
	import global_wyx from '../../../../../../components/tool/licaishiwyx'
	import global_ from '../../../../../../components/tool/Global'
	import timePicker from '../../../../../../components/picker/picker.vue'
	export default {
		components:{
			timePicker
		},
		data() {
			return {
				checked:true,
				customer:{custno:'',name:''},
				balance:'',
				token:uni.getStorageSync('token_key'),
				loginRole:'',
				yuyueId:'',
				proName:'',
				canIclick:true
			};
		},
		onLoad(option){
			console.info(JSON.stringify(option))
			this.proj_id = option.proj_id;
			this.proName = option.proName;
		},
		//页面退回调用
		onBackPress(){
			console.info("页面退出。。。。。。。。。。。。。。。.")
			this.$eventHub.$off('fire');
		},
		onShow(){
// 			console.info("123123123")
// 			//监听‘fire’是否有变化
// 			var obj = new Object(); 
// 			var cc = this.$eventHub.$on('fire', (item)=>{
// 				console.log("收到事件"+JSON.stringify(item))
// 				this.customer = item
// 			});
// 			console.info(this.customer)
		},
		methods:{
			showTime(res){
				console.info(JSON.stringify(res))
			},
			checkedTab(){
				this.checked=!this.checked
			},
			selectCustom(){
				uni.navigateTo({
					url: './../../../../../my/lcs-wodekehu/lcs-wodekehu',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
				console.info("123123123")
				//监听‘fire’是否有变化
				var obj = new Object(); 
				var cc = this.$eventHub.$on('fire', (item)=>{
					console.log("收到事件"+JSON.stringify(item))
					this.customer = item
				});
				console.info(this.customer)
			},
			tijiao(){
				var canTijiao = true;
				var tipMessage = "";
				
				if(this.customer.name==""){
					tipMessage = "请选择客户"
					canTijiao = false;
				}
				if(this.balance==0){
					tipMessage = "请输入预约金额"
					canTijiao = false;
				}
				
				if(!canTijiao){
					uni.showToast({
						title: tipMessage,
						icon: 'none',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
					return;
				}
				
				if(!this.canIclick){
					return;
				}
				this.canIclick = false;
				uni.request({
					url: global_wyx.api.licaishi_yuYue, 
					method:'POST',
					header : {'content-type':'application/x-www-form-urlencoded'},
					data: {
						custid: this.customer.custno,
						proj_id:this.proj_id,
						balance:this.balance,
						token:this.token,
						isRisk:'N'
					},
					
					dataType:'json',
					success: (res) => {
						var code=res.data.code;
						var message1=res.data.message;
						console.log("返回结果"+JSON.stringify(res.data));
						this.doRuslt(res);
						//客户风险等级与产品风险等级不匹配 弹出确定取消对话框（提示信息为返回的sreasoninfo），点确定后调用接口PKG_YL_HIS_DATA.sp_appaddtreserve_risk,参数与PKG_YL_HIS_DATA.sp_appaddtreserve相同 跳转到购买流程页面，点取消留到当前页面
						if(code=='4'){
							uni.showModal({
								title: '',
								content: message1,
								showCancel: true,
								success: res => {
									if(res.confirm){
										uni.request({
											url: global_wyx.api.licaishi_yuYue, 
											method:'POST',
											header : {'content-type':'application/x-www-form-urlencoded'},
											data: {
												custid: this.customer.custno,
												proj_id:this.proj_id,
												balance:this.balance,
												token:this.token,
												isRisk:'Y'
											},
											
											dataType:'json',
											success: (res) => {
												var code=res.data.code;
												var message=res.data.message;
												console.log("返回结果"+JSON.stringify(res.data));
												this.doRuslt(res);
											},
											fail:(res) => {},
											complete:(res) => {}
										})
									}else{
										if(res.cancel){
											console.info("不做任何操作")
											return;
										}
									}
								},
								fail: () => {},
								complete: () => {}
							});
						}
					},fail:(res) => {
						console.log("fail");
						//console.log(res.data);
						this.text = 'request fail';
					},complete:(res) => {
						setTimeout(() => {
						  this.canIclick = true;
						  console.info("现在可以点击。。。。。。。。。")
						}, 10000)
					}
				});
			},
			doRuslt(res){
				var code=res.data.code;
				var message=res.data.message;//调用孙总的存储过程，成功返回预约编号，失败返回失败原因
				console.log("返回结果"+JSON.stringify(res.data));
				var sunzongMessage=message.toString();
				if(code=='1'){
					//预约编号 
					var getyuyueId = sunzongMessage;
					console.info("预约编号："+getyuyueId)
					this.yuyueId = getyuyueId;
					uni.request({
						url: global_wyx.api.getYuyueStatussunzong, 
						method:'POST',
						header : {'content-type':'application/x-www-form-urlencoded'},
						data: {
							// custid: this.customer.custno,
							projid:this.proj_id,
							yuyueid:this.yuyueId
						},
						
						dataType:'json',
						success: (res) => {
							var code=res.data.code;
							var resultData = res.data.data;
							console.info("孙总存错过程："+resultData)
							var messageName = resultData.split("|")[0];
							var messageCode = resultData.split("|")[1];
							
							var param = "?projId="+this.proj_id+"&balance="+this.balance+"&custid="+this.customer.custno+"&custname="+this.customer.name+"&yuyueId="+this.yuyueId+"&proName="+this.proName+'&status='+messageCode
							console.info("传递参数"+param)
							var isSiMu=uni.getStorageSync('isSiMu');
							var toUrl = "";
							console.info("isSiMu:"+isSiMu)
							if(isSiMu==0){
								toUrl = '../baoliYuyue';
							}else if(isSiMu==1){
								toUrl = '../simuYuyue';
							}
							toUrl+=param;

							uni.showToast({
								title:messageName,
								icon:"success"
							});
							setTimeout(() => {
							  uni.navigateTo({
							  		url: toUrl,
							  		success: res => {},
							  		fail: () => {},
							  		complete: () => {}
							  });
							}, 500)
						},fail:(res) => {
						},complete:(res) => {
						}
					})
				}//2、未做投资者认证 本期先跳转到客户详情页面 //3、未做风险测评或需要重新风险测评 本期先跳转到客户详情页面
				else if(code=='2' || code=='3'){
					uni.showModal({
						title: '',
						content: sunzongMessage,
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								uni.navigateTo({
										url: '../../../../../my/lcs-wodekehu/kehuxiangqing/kehuxiangqing?news_Id='+this.customer.custno,
										success: res => {
										},
										fail: () => {},
										complete: () => {
										}
								});
							}
						}
					});
				}//其他
				else if(code=='0'){
					uni.showToast({
						title:sunzongMessage,
						icon:"none"
					});
					return;
				}
				else if(code=='3005'){
					uni.showModal({
						title: '',
						content: sunzongMessage,
						showCancel: false,
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			}
		},
// 		onHide(){
// 			console.info("onHide")
// 			this.canIclick = true;
// 		},
// 		onUnload(){
// 			console.info("onUnload")
// 			this.canIclick = true;
// 		}

	}

</script>

<style>
	page {
		background: rgb(255, 255, 255);
	}
	.title{
		text-align: center;
		line-height: 100upx;
		font-size: 17px;
		color:rgba(51,51,51,1);
	}
	.box{
		padding: 0 30upx;
	}
	.shiming {
		background: #f5f5f5;
		height: 20upx;
		
	}
	
	.username {
		color: #000000;
		opacity: 1;
	}
	.row {
		height: 98upx;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.row input{
		flex: 3;
	}
	.left {
		font-size: 15px;
		margin-right: 20px;
		flex: 1;
	}
	.right{
		min-width: 520upx;
	}
	.inputMoney {
		padding-left: 10px;
	}
	.questionBox {
		display: flex;
		flex-direction: row;
		justify-content: center;
		width: 100%;
		padding: 40upx 0;
		text-align: center;
		

	}

	.question {
		margin: 0 20upx;
		width: 240upx;
		height: 70upx;
		background: linear-gradient(-90deg, rgba(196, 156, 90, 1) 0%, rgba(226, 196, 138, 1) 100%);
		border-radius: 35px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		color: rgb(255, 255, 255);

	}

	.icon {
		margin-right: 10upx;
	}
	
</style>
